import { computed } from "vue";

/**
 * props数据双向绑定
 * @param props
 * @param name
 * @param emit
 * @returns
 */
export default function useVModel<P extends object, N extends keyof P, E extends (event: string, value: P[N]) => void>(
	props: P,
	name: N,
	emit: E
) {
	const model = computed({
		get() {
			return props[name];
		},
		set(val) {
			emit(`update:${name as string}`, val);
		}
	});

	return model;
}
